--祈福
---@class UIRanking_PlayerInfo : UIComponentBase
local PlayerInfo = Class("PlayerInfo",UIComponentBase)
local t = PlayerInfo

function t:OnCreate(index)
    self.index=index
    self.btnLike=self:GetChild("btnLike");
    self.name=self:GetChild("name");
    self.power1=self:GetChild("power1");
    self.checkInfo=self:GetChild("checkInfo");
    self.power2=self:GetChild("power2");
    self.position=self:GetController("position");
    self.raking=self:GetController("raking");
    self.numLike=self.btnLike:GetChild("numLike");
    self.headobj = self:GetChild("head")
    self.head = self:GetChild("head/head/HeadIcon")
    self.frame = self:GetChild("head/frame")
    self.unionName = self:GetChild("nameGuild")
    self.unionName2 = self:GetChild("nameGuild2")
    self.name2=self:GetChild("name2");
    self.unionCtrl = self:GetController("showGuild")
end
function t:GotOtherShowInfo(info)
    showUI(PanelNames.UIPlayerShow, info,nil,false,function()
        UIBottom.onClickTown();
        showUI(PanelNames.UIRanking)
    end)
end

function t:InitData(data)
    if data==nil then
        UIRedDots.addViewListen(PanelResNames.UIRanking, self.fguiObj.name .. self.btnLike.name, self.btnLike, Config.RedDotsType.UIRankingLike,true)
        return
    end
    self.data=data;
    self.playerShowInfo=data.playerShowInfo
    self:Refresh()
    if self.data.playerShowInfo ~= nil and logicMgr.NoticeManager.selfInfo.playerShowInfo.playerId~=self.data.playerShowInfo.playerId then
        self:RegisterOnClick(self.checkInfo,self.InfoMes,self)
        self:RegisterOnClick(self.headobj,self.InfoMes,self)
    end
    self:RegisterOnClick(self.btnLike,self.ClickBless,self)
    UIRedDots.addViewListen(PanelResNames.UIRanking, self.fguiObj.name .. self.btnLike.name, self.btnLike, Config.RedDotsType.UIRankingLike)
    self:RegisterEvent(Config.EventType.FreashRoleInfoOther, self.GotOtherShowInfo);
end
function t:InfoMes()
    roleInfoHandler.sendreqOtherRoleInfo(self.data.playerShowInfo.playerId)
end

function t:OnEnable()
    
end
function t:OnDisable()
    self:UnRegisterEvent();
end
function t:OnDestroy()
end
function t:Refresh()
    if self.index%2==0 then
        self.position.selectedIndex=1;
        self.power2.text=getNumString(self.data.parameter);
    else    
        self.position.selectedIndex=0;       
        self.power1.text=getNumString(self.data.parameter);
    end
    if self.playerShowInfo ~= nil then
        self.name.text= self.playerShowInfo and self.playerShowInfo.name or getLanguage("BillboardRankNeedPlayer")
        self.name2.text = self.playerShowInfo and self.playerShowInfo.name or getLanguage("BillboardRankNeedPlayer")
        self.numLike.text= getNumString(tonumber(self.data.extend1));
        self.head.url= logicMgr.SkinManager.GetHeroIconBySkinId(self.playerShowInfo.pic)
        self.frame.url = "ui://ICONAtlas/" .. self.playerShowInfo.picFrame;
        if self.playerShowInfo.unionName then
            self.unionCtrl.selectedIndex = 1
            self.unionName.text = "<"..self.playerShowInfo.unionName..">"
            self.unionName2.text = "<".. self.playerShowInfo.unionName..">"
        else
            self.unionCtrl.selectedIndex = 0
        end
    end
end
function t:RefreshNoticeBless()
    self:Refresh()
end
function t:ClickBless()
    if self.data and self.data.playerShowInfo then
        local day_like_count = G.dataTable["t_global"][tostring(305)].f_int_value or 0
        if  logicMgr.NoticeManager.dayClick < day_like_count then
            NoticeHandler.ReqGivePraise(self.data.playerShowInfo.playerId) 
        else
            UISysTips.AddMsg(getLanguage("UIRanking05"))
        end
    end
end
return t